﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T02
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] num = { 1, 2, 3, 4, 5, -1, 100, 6, 7, 8, 9, 10 };
            int[] num1 = new int[13];
            Array.Output(num);
            Console.WriteLine("查找索引值为{0}", Array.Search(1, num));
            Console.WriteLine("插入排序");
            Array.InsertSort(11,num1,num);
            Console.ReadKey();
        }
    }
    class Array
    {

        public static void Output(params int[] values)
        {
            for (int j = 0; j < values.Length; j++)

            {

                Console.Write(values[j] + " ");

            }
        
        }
        public static int? Search(int a, params int[] values)
        {
            int i = 0;
            while (a != values[i] && i < values.Length)
            {
                i++;
            }
            if (i == values.Length) return null;
            else return i;
        }
        public static void InsertSort(int k, int[] values, int [] values1)
        {
            int temp,q=0;
            for (int p = 0; p < values1.Length; p++)
            {
                values[p] = values1[p];
            }
                for (int i = 0; i < values.Length; i++)
                for (int j = i + 1; j < values.Length; j++)
                {
                    if (values[i] > values[j])
                    {
                        temp = values[i];
                        values[i] = values[j];
                        values[j] = temp;
                    }

                }
            while(k> values[q])
            {
                q++;
            }

            int u ;
            
            for (u = values.Length -1;u>=q;u--)
            {
                values[u] = values[u-1];
            }
            values[q] = k;
            for (int j = 0; j < values.Length; j++)

            {
                Console.Write(values[j] + " ");

            }

        }
    }
}